import os
import sys
from pathlib import Path
import django


def main() -> None:
    # 确保项目根目录在 sys.path 中
    project_root = Path(__file__).resolve().parents[1]
    if str(project_root) not in sys.path:
        sys.path.insert(0, str(project_root))

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
    django.setup()
    from django.contrib.auth import get_user_model

    user_model = get_user_model()
    user, _ = user_model.objects.get_or_create(username="admin", defaults={"is_superuser": True, "is_staff": True, "email": "admin@example.com"})
    user.set_password("admin123456")
    user.is_superuser = True
    user.is_staff = True
    if not user.email:
        user.email = "admin@example.com"
    user.save()
    print("Admin password set to: admin123456")


if __name__ == "__main__":
    main()


